package com.bougaga.opensource.scheduler.springboot.autoconfigure;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * Bou Scheduler 配置属性
 * 
 * @author bougaga
 * @since 1.0.0
 */
@ConfigurationProperties(prefix = "bou.scheduler")
public class BouSchedulerProperties {
    
    /**
     * 是否启用调度器
     */
    private boolean enabled = true;
    
    /**
     * 时间轮配置
     */
    private TimeWheel timeWheel = new TimeWheel();
    
    /**
     * 线程池配置
     */
    private ThreadPool threadPool = new ThreadPool();
    
    /**
     * 任务配置
     */
    private Task task = new Task();
    
    /**
     * 清理配置
     */
    private Cleanup cleanup = new Cleanup();
    
    /**
     * Web配置
     */
    private Web web = new Web();
    
    public boolean isEnabled() {
        return enabled;
    }
    
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }
    
    public TimeWheel getTimeWheel() {
        return timeWheel;
    }
    
    public void setTimeWheel(TimeWheel timeWheel) {
        this.timeWheel = timeWheel;
    }
    
    public ThreadPool getThreadPool() {
        return threadPool;
    }
    
    public void setThreadPool(ThreadPool threadPool) {
        this.threadPool = threadPool;
    }
    
    public Task getTask() {
        return task;
    }
    
    public void setTask(Task task) {
        this.task = task;
    }
    
    public Cleanup getCleanup() {
        return cleanup;
    }
    
    public void setCleanup(Cleanup cleanup) {
        this.cleanup = cleanup;
    }
    
    public Web getWeb() {
        return web;
    }
    
    public void setWeb(Web web) {
        this.web = web;
    }
    
    /**
     * 时间轮配置
     */
    public static class TimeWheel {
        
        /**
         * 时间轮刻度间隔（毫秒）
         */
        private long tickDuration = 100;
        
        /**
         * 时间轮大小
         */
        private int wheelSize = 512;
        
        public long getTickDuration() {
            return tickDuration;
        }
        
        public void setTickDuration(long tickDuration) {
            this.tickDuration = tickDuration;
        }
        
        public int getWheelSize() {
            return wheelSize;
        }
        
        public void setWheelSize(int wheelSize) {
            this.wheelSize = wheelSize;
        }
    }
    
    /**
     * 线程池配置
     */
    public static class ThreadPool {
        
        /**
         * 核心线程数
         */
        private int corePoolSize = Runtime.getRuntime().availableProcessors();
        
        /**
         * 最大线程数
         */
        private int maxPoolSize = Runtime.getRuntime().availableProcessors() * 2;
        
        /**
         * 队列容量
         */
        private int queueCapacity = 10000;
        
        /**
         * 线程空闲时间（秒）
         */
        private long keepAliveTime = 60;
        
        public int getCorePoolSize() {
            return corePoolSize;
        }
        
        public void setCorePoolSize(int corePoolSize) {
            this.corePoolSize = corePoolSize;
        }
        
        public int getMaxPoolSize() {
            return maxPoolSize;
        }
        
        public void setMaxPoolSize(int maxPoolSize) {
            this.maxPoolSize = maxPoolSize;
        }
        
        public int getQueueCapacity() {
            return queueCapacity;
        }
        
        public void setQueueCapacity(int queueCapacity) {
            this.queueCapacity = queueCapacity;
        }
        
        public long getKeepAliveTime() {
            return keepAliveTime;
        }
        
        public void setKeepAliveTime(long keepAliveTime) {
            this.keepAliveTime = keepAliveTime;
        }
    }
    
    /**
     * 任务配置
     */
    public static class Task {
        
        /**
         * 默认最大重试次数
         */
        private int defaultMaxRetryCount = 3;
        
        /**
         * 默认重试间隔（毫秒）
         */
        private long defaultRetryInterval = 5000;
        
        /**
         * 任务过期时间（天）
         */
        private int expirationDays = 7;
        
        public int getDefaultMaxRetryCount() {
            return defaultMaxRetryCount;
        }
        
        public void setDefaultMaxRetryCount(int defaultMaxRetryCount) {
            this.defaultMaxRetryCount = defaultMaxRetryCount;
        }
        
        public long getDefaultRetryInterval() {
            return defaultRetryInterval;
        }
        
        public void setDefaultRetryInterval(long defaultRetryInterval) {
            this.defaultRetryInterval = defaultRetryInterval;
        }
        
        public int getExpirationDays() {
            return expirationDays;
        }
        
        public void setExpirationDays(int expirationDays) {
            this.expirationDays = expirationDays;
        }
    }
    
    /**
     * 清理配置
     */
    public static class Cleanup {
        
        /**
         * 是否启用自动清理
         */
        private boolean enabled = true;
        
        /**
         * 清理间隔（小时）
         */
        private int intervalHours = 24;
        
        /**
         * 清理保留天数
         */
        private int retentionDays = 7;
        
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public int getIntervalHours() {
            return intervalHours;
        }
        
        public void setIntervalHours(int intervalHours) {
            this.intervalHours = intervalHours;
        }
        
        public int getRetentionDays() {
            return retentionDays;
        }
        
        public void setRetentionDays(int retentionDays) {
            this.retentionDays = retentionDays;
        }
    }
    
    /**
     * Web配置
     */
    public static class Web {
        
        /**
         * 是否启用Web功能
         */
        private boolean enabled = true;
        
        /**
         * 服务器配置
         */
        private Server server = new Server();
        
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public Server getServer() {
            return server;
        }
        
        public void setServer(Server server) {
            this.server = server;
        }
        
        /**
         * 服务器配置
         */
        public static class Server {
            
            /**
             * 应用名称
             */
            private String applicationName = "bou-scheduler";
            
            public String getApplicationName() {
                return applicationName;
            }
            
            public void setApplicationName(String applicationName) {
                this.applicationName = applicationName;
            }
        }
    }
}
